package com.lottery.ruok.lottrey.dialog;

import android.animation.Animator;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListAdapter;

import com.airbnb.lottie.LottieAnimationView;
import com.applozic.mobicomkit.ChatConfig;
import com.lottery.ruok.lottrey.R;
import com.lottery.ruok.lottrey.activity.AccountDetailActivity;
import com.lottery.ruok.lottrey.activity.GetPacketResultActivity;
import com.lottery.ruok.lottrey.ui.MyGridView;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by ASUS on 2017/8/2.
 */

public class AwardAniDialog extends Activity {
    @BindView(R.id.anim)
    LottieAnimationView anim;
    @BindView(R.id.ll_money)
    LinearLayout llmoney;
    private String flag;
    private String money;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.award_lottie_layout);
        ButterKnife.bind(this);
        Intent intent = getIntent();
        flag = intent.getStringExtra("flag");
        money = intent.getStringExtra("money");
        initView();
    }

    private void initView() {
        char[] moneyArray = money.toCharArray();
        for (char c : moneyArray) {
            switch (c) {
                case '0':
                    llmoney.addView(getImageView(R.mipmap.number_0));
                    break;
                case '1':
                    llmoney.addView(getImageView(R.mipmap.number_1));
                    break;
                case '2':
                    llmoney.addView(getImageView(R.mipmap.number_2));
                    break;
                case '3':
                    llmoney.addView(getImageView(R.mipmap.number_3));
                    break;
                case '4':
                    llmoney.addView(getImageView(R.mipmap.number_4));
                    break;
                case '5':
                    llmoney.addView(getImageView(R.mipmap.number_5));
                    break;
                case '6':
                    llmoney.addView(getImageView(R.mipmap.number_6));
                    break;
                case '7':
                    llmoney.addView(getImageView(R.mipmap.number_7));
                    break;
                case '8':
                    llmoney.addView(getImageView(R.mipmap.number_8));
                    break;
                case '9':
                    llmoney.addView(getImageView(R.mipmap.number_9));
                    break;

            }
        }
    }

    private View getImageView(int imageResId) {
        ImageView imageView = new ImageView(this);
        imageView.setBackgroundResource(imageResId);
        return imageView;
    }

    @Override
    protected void onResume() {
        super.onResume();

//        anim.playAnimation();
        anim.useHardwareAcceleration(true);
        anim.addAnimatorListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animator) {

            }

            @Override
            public void onAnimationEnd(Animator animator) {
                anim.enableMergePathsForKitKatAndAbove(true);
                try {
                    if (flag == null) {
                        Intent intent = new Intent(AwardAniDialog.this, GetPacketResultActivity.class);
                        intent.putExtra(ChatConfig.PACKET_GET_ID, getIntent().getStringExtra(ChatConfig.PACKET_GET_ID));
                        intent.putExtra(ChatConfig.PACKET_ID, getIntent().getStringExtra(ChatConfig.PACKET_ID));
                        startActivity(intent);
                    } else {
                        Intent intent_red = new Intent(AwardAniDialog.this, AccountDetailActivity.class);
                        startActivity(intent_red);
                    }

                } catch (Exception e) {
                    e.printStackTrace();
                }

                finish();
            }

            @Override
            public void onAnimationCancel(Animator animator) {

            }

            @Override
            public void onAnimationRepeat(Animator animator) {

            }
        });
    }

    @Override
    public void onBackPressed() {

    }
}
